<?php
namespace app\walletyhbbadmin\controller;
use think\Db;
require_once (APP_PATH . 'api/RewardApi.php');
require_once (APP_PATH . 'api/FinanceApi.php');
class Orders extends AdminBase{
    //空操作
    public function _empty(){
        header("HTTP/1.0 404 Not Found");
        $this->display('Public:404');
    }
   
    /**
     * 订单列表
     */
    public function index(){
        $number=input('number');
        if(!empty($number)){
            $where['order_sn']=array('like','%'.$number.'%');
        }
        $orders = DB::name('Order')->where($where)->order('add_time desc')->paginate(15,false,['query'=>input()]);
        $arr =  DB::name('Users')->select();
        $page = $orders->render ();
        $orders = $orders->all();
        foreach($orders as $k=>$v){
            $orders[$k]['nickname'] = DB::name('users')->where('user_id',$v['user_id'])->value('nickname');
        }
        $this->assign('orders',$orders);
        $this->assign('page',$page);
        return $this->fetch('orders/tradeIng');
    }
    // 收款
    public function shoukuan(){
        $where['order_id']=input('id');
        $status['order_status']='1';
        $res=Db::name('order')->where($where)->update($status);
        if($res){
            $this->success('确认收款成功');
        }else{
            $this->error('系统繁忙');
        }
    }
    //删除订单
    public function delete(){
        $where['order_id'] = input('id');
//        dump($where);
        $data['order_status'] = '3';
        $bool = DB::name('order')->where($where)->update($data);
        if($bool){
            $this->success('删除成功');
        }else{
            $this->error('系统繁忙');
        }
    }

    //查看订单详情
    public function xiangqing(){
        $where['order_id'] = input('id');
        $orders = DB::name('delivery_doc')->where($where)->select();
        foreach($orders as $k=>$v)
        {
            $orders[$k]['goods_name'] = DB::name('order_goods')->where('order_id',$orders[$k]['order_id'])->value('goods_name');
        }
        $this->assign('orders',$orders);
        return $this->fetch('orders/xiangqing');
    }

    //查看发票详情
    public function fapiao(){
        $where['order_id'] = input('id');
        $fapiao = DB::name('Order')->where($where)->find();
        $name = DB::name('users')->where('user_id',$fapiao['id'])->find();
        $this->assign('info',$fapiao);
        return $this->fetch('orders/fapiao');
    }
}